<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\readlinks;
use DB;

class ReadlinksController extends Controller
{
      public function index()
      {
        $readlinks = DB::table('readlinks')->orderBy('family')->where('deleted_at','=',NULL)->get();
        $readlinks_f = DB::table('readlinks')->orderBy('family')->where('deleted_at','<>',NULL)->get();
        return view('backend.readlink.index',compact('readlinks','readlinks_f'));
      }

      public function store(Request $request)
      {
        $this->validate($request,[
          'name'=>'required',
          'family'=>'required',
          'href'=>'required',
          'src'=>'required'
        ]);

        $readlinks = readlinks::create([
          'name'=> $request->name,
          'href'=> $request->href,
          'src'=> $request->src,
          'family'=> $request->family
        ]);
        session()->flash('success','阅读链接创建成功！');
        return redirect()->back();
      }

      public function destroy($id)
    {

      $readlinks = readlinks::findOrFail($id);
      $readlinks->delete();
      session()->flash('success','阅读链接删除成功！');
      return redirect()->back();
    }
}
